layui.use('form', function () {
    var form = layui.form
    console.log("执行一次layui，form");
    form.on('submit(editformGo)',function (data){
        var data2 = JSON.stringify(data.field);
        $.ajax({
            url: "/webapi/ich/edit",
            type: "post",
            data: data2,
            contentType:' application/json;charset=UTF-8',
            success: function (rs) {
                if(rs.code > 0){
                    if(parent != null){
                        parent.layer.closeAll();
                        parent.location.reload();
                    }
                }
            }
        })
        event.preventDefault();
    })
})

$(function () {
        var url = window.location.href; //取当前页面地址
        //http://localhost:8080/ich/edit/1

        var urlsplit = url.split("/");
        var len = urlsplit.length;
        var idstr = urlsplit[len-1];
        console.log("执行一次");
        $.ajax({
            url: "/webapi/ich/"+idstr,
            method: "get",
            success: function (rs){
                if(rs.code >= 0){
                    data = rs.data;
                    //正确取到学生的信息到rs中
                    $("#id").val(data.id);
                    $("#name").val(data.name);
                    $("#category").val(data.category);
                    $("#nation").val(data.nation);
                    $("#location").val(data.location);
                    $("#inheritors").val(data.inheritors);
                    if(data.level === "国家级"){
                        $("#level1").attr("checked", true);
                    }else{
                        $("#level2").attr("checked", true);
                    }
                    $("#appliances").val(data.appliances);
                    $("#description").val(data.description);
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    })
                }else{
                    alert(data.msg);
                }
            }
        })

});



